home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / andere sprachen / gamesmaster / demosrc / sprites.s < prev    next >
Text File  |  1996-07-16  |  5KB  |  149 lines

  1. ;Sprite example
  2. ;--------------
  3. ;This example shows you how to set up a 16 colour OCS sprite with a doubled
  4. ;X axis (32 pixels width).  Those with hardware experience will know that it
  5. ;takes 4 sprite banks to do this successfully in OCS, which leaves you with
  6. ;another 4 banks to do with what you will.
  7. ;
  8. ;Notice that the screen is only 1 bitplane large, even though the sprite is
  9. ;16 colours.  This is because the sprite is independent of the screen
  10. ;bitmap.  You can access colours not in the screen by setting up a large
  11. ;palette and specifying the amount of colours in SS_AmtColours (in this
  12. ;case, we set 32 colours to access the sprite colour bank).
  13. ;
  14. ;Also, try moving the sprite around a bit with the mouse.
  15.  
  16.     opt    o+
  17.  
  18.     INCLUDE    "exec/exec_lib.i"
  19.     INCLUDE    "games/games_lib.i"
  20.     INCLUDE    "games/games.i"
  21.     INCLUDE    "games/gamesbase.i"
  22.  
  23. CALL    MACRO
  24.     jsr    _LVO\1(a6)
  25.     ENDM
  26.  
  27.     SECTION    "Sprites",CODE
  28.  
  29. ;===========================================================================;
  30. ;                             INITIALISE DEMO
  31. ;===========================================================================;
  32.  
  33. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  34.     move.l    ($4).w,a6
  35.     lea    GMS_Name(pc),a1
  36.     moveq    #$00,d0
  37.     CALL    OpenLibrary
  38.     move.l    d0,GMS_Base
  39.     beq.s    Error
  40.  
  41.     move.l    GMS_Base(pc),a6          ;Run this demo at a user-selected
  42.     CALL    SetUserPri               ;priority.
  43.  
  44.     lea    ScreenStruct(pc),a0      ;Initialise our screen for use.
  45.     CALL    Add_Screen
  46.     tst.l    d0
  47.     bne.s    Error
  48.  
  49.     CALL    Show_Screen              ;Show our screen.
  50.  
  51.     lea    SparkieStruct(pc),a1
  52.     CALL    Init_Sprite
  53.     CALL    Update_Sprite            ;First get him onto the screen.
  54.  
  55. ;===========================================================================;
  56. ;                                MAIN LOOP
  57. ;===========================================================================;
  58.  
  59. Loop:    addq.w    #1,d7                    ;Animation/Frame delay, so that
  60.     btst    #0,d7                    ; our anim does not run too fast!
  61.     beq.s    .Mouse
  62.     cmp.w    #5,SPR_Frame(a1)         ;Do the animation for the sprite.
  63.     beq.s    .reset                   ;(simply by increasing the frame
  64.     addq.w    #1,SPR_Frame(a1)         ; number).
  65.     bra.s    .Mouse
  66. .reset    clr.w    SPR_Frame(a1)
  67.  
  68. .Mouse    moveq    #JPORT1,d0               ;Read from port 1
  69.     CALL    Read_Mouse               ;Go get mouse position.
  70.     move.l    d0,SPR_XPos(a1)          ;Update the X/Y positions in one go.
  71.  
  72.     CALL    Wait_OSVBL               ;Allow screen-switching.
  73.     CALL    Update_Sprite            ;Put Sparkie on the screen.
  74.  
  75.     btst    #M_LMB,MouseButtons1+1(a6)
  76.     beq.s    Loop
  77.  
  78. ;===========================================================================;
  79. ;                              RETURN TO DOS
  80. ;===========================================================================;
  81.  
  82. .done    CALL    Delete_Screen            ;Give back screen memory etc.
  83. Error    move.l    GMS_Base(pc),a1
  84.     move.l    ($4).w,a6
  85.     CALL    CloseLibrary
  86. Quit    MOVEM.L    (SP)+,A0-A6/D1-D7
  87.     moveq    #$00,d0
  88.     rts
  89.  
  90. ;===========================================================================;
  91. ;                                  DATA
  92. ;===========================================================================;
  93.  
  94. GMS_Name:
  95.     dc.b    "games.library",0
  96.     even
  97. GMS_Base:
  98.     dc.l    0
  99.  
  100. SparkieStruct:
  101.     dc.w    0                        ;Number 0.
  102.     dc.l    Gfx_Sparkie              ;Ptr to graphic.
  103.     dc.w    100,100                  ;Beginning X/Y position
  104.     dc.w    0                        ;Current frame.
  105.     dc.w    16                       ;Width (16/32/64)
  106.     dc.w    21                       ;Height
  107.     dc.w    16                       ;Amt of colours.
  108.     dc.w    16                       ;Colour start in palette.
  109.     dc.w    4                        ;Amt of planes.
  110.     dc.w    SPR_OCS|LORES|XLONG      ;Attributes.
  111.     dc.l    0,0,0,0                  ;Private.
  112.  
  113. AMT_PLANES =    1
  114.  
  115. ScreenStruct:
  116.     dc.l    "GSV1"
  117.     dc.l    0,0,0                    ;Screen_Mem1/2/3
  118.     dc.l    0                        ;Screen link.
  119.     dc.l    ScreenPalette            ;Address of the screen palette.
  120.     dc.l    0                        ;Address of a ColourList.
  121.     dc.l    32                       ;Amt of colours in the palette.
  122.     dc.w    256,320,320/8            ;Screen Height, Width, Width/8
  123.     dc.w    256,320,320/8            ;Pic Height, Width, Width/8
  124.     dc.w    AMT_PLANES               ;Amt_Planes
  125.     dc.w    0,0                      ;Top Of Screen, X/Y
  126.     dc.w    0                        ;Scroll buffer in pixels/8.
  127.     dc.w    0,0                      ;X/Y counters (for scrolling).
  128.     dc.l    NOBURST|SPRITES|NOSPRBDR ;Special attributes.
  129.     dc.w    LORES                    ;Screen mode.
  130.     dc.b    INTERLEAVED              ;Screen type
  131.     dc.b    0                        ;Screen Is Being Displayed?
  132.     dc.l    0,0                      ;Reserved area.
  133.     even
  134.  
  135. ScreenPalette:
  136.     dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
  137.     dc.w    $0000,$0688,$0466,$0344,$0CC0,$0980,$0870,$0650
  138.     dc.w    $01C2,$0050,$0B0B,$0606,$0F20,$0910,$0BBB,$0FFF
  139.     dc.w    $00BF,$0068,$0568,$09BF,$0FF0,$0EE0,$0BA0,$0540
  140.  
  141. ;===========================================================================;
  142. ;                         ALL CHIP RAM DATA HERE
  143. ;===========================================================================;
  144.  
  145.     SECTION    "Graphics",DATA_C
  146.  
  147. Gfx_Sparkie:
  148.     INCBIN    "GAMESLIB:Store/Sparkie.raw"
  149.